﻿#ifndef MAINFRAME_H
#define MAINFRAME_H
#include<QWindow>
#include <QQuickView>
#include<QResizeEvent>
#include "XuanCommon_global.h"
#include <QMouseEvent>
#include<QtDebug>
#include<QObject>
class framePrivate;
class XUANCOMMON_EXPORT MainFrame : public QQuickView
{
    Q_PROPERTY(bool isMax READ isMax WRITE setIsMax NOTIFY isMaxChanged)
    Q_OBJECT
    using Super = QQuickView;
public:
    explicit MainFrame(QWindow *parent = nullptr);
    ~MainFrame();
    void QResizeEvent(QResizeEvent *e){Super::resizeEvent(e);}

#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
    bool nativeEvent(const QByteArray &eventType, void *message, qintptr *result) override;
# else
    bool nativeEvent(const QByteArray &eventType, void *message, long *result) override;
#endif
protected:
    void   mousePressEvent(QMouseEvent *e) override{
        emit mousePressed(e->x(),e->y(),e->buttons());
        Super::mousePressEvent(e);
    }


public:
    ///
    /// \brief MainFrame::calcCenterGeo
    /// \param screenGeo 窗口可用大小
    /// \param normalSize 不包括框架的窗口大小
    /// \return
    ///
    static QRect calcCenterGeo(const QRect &screenGeo,const QSize &normalSize);
public:
    void moveToScreenCenter();
    bool isMax() const;
    void setIsMax(bool isMax);
    QQuickItem *titleItem()const; //自定义item
public slots:
    void setTitleItem(QQuickItem *item);

signals:
    void isMaxChanged(bool isMax);
    void mousePressed(int xPos,int yPos,int btn);

private:
    framePrivate * fp;
};


#endif // MAINFRAME_H
